package mao.leetcode.others.leetcode303;

public class NumArray {
    int[] data;
    public NumArray(int[] nums) {
        this.data = new int[nums.length+1];
        for (int i = 1; i < data.length; i++) {
              data[i]=data[i-1]+nums[i-1];
        }
    }

    public int sumRange(int i, int j) {
        int res =0;
        if (i<0 || j>= data.length-1) return 0;
        return data[j+1]-data[i];
    }
}
